<template>
  <div class="margin-top">
    <Header @changeLanguage="changeLanguage" />
    <Title :pageName="title" />
    <SubTitle :pageName="sub_title0" />
    <div class="desc-main" v-html="desc"></div>
    <SubTitle :pageName="sub_title1" />
    <div class="list">
      <div class="item" v-for="(item, index) in list1" :key="index">
        <div class="logo">
          <img :src="item.logoUrl" />
        </div>
        <div class="name">{{ item.name }}</div>
        <div class="desc">{{ item.desc }}</div>
        <div class="link">
          <a :href="item.url" target="_blank">{{ link }}</a>
        </div>
      </div>
    </div>
    <SubTitle :pageName="sub_title2" />
    <div class="list">
      <div class="item" v-for="(item, index) in list2" :key="index">
        <div class="logo">
          <img :src="item.logoUrl" />
        </div>
        <div class="name">{{ item.name }}</div>
        <div class="desc">{{ item.desc }}</div>
        <div class="link">
          <a :href="item.url" target="_blank">{{ link }}</a>
        </div>
      </div>
    </div>
    <Footer />
  </div>
</template>

<script>
import { introduction } from "@/lang";
import Header from "@/components/Header";
import Title from "@/components/Title";
import Footer from "@/components/Footer";
import SubTitle from "@/components/SubTitle";
import { getInstituteList,getInstituteIntroduction } from "@/api";
export default {
  name: "instituteIntroduction",
  components: {
    Header,
    Title,
    Footer,
    SubTitle,
  },
  data() {
    return {
      langCode: "",
      title: "",
      link: "",
      introduction: introduction,
      list1: [],
      list2: [],
      sub_title1: "",
      sub_title2: "",
      sub_title0: "",
      desc: "",
    };
  },
  created() {
    const lang = localStorage.getItem("lang");
    this.langCode = lang === "ZH" ? 0 : 1;
    this.setPageLanguage(lang);
    this.onSend();
  },
  methods: {
    onSend() {
      this.getList();
      this.getDesc();
    },
    async getList() {
      let self = this;
      const res = await getInstituteList({
        lang: self.langCode,
      });
      res.department_1.forEach((item) => {
        item.logoUrl = `${process.env.VUE_APP_BASE_API}/${item.logo}`;
      });
      res.department_2.forEach((item) => {
        item.logoUrl = `${process.env.VUE_APP_BASE_API}/${item.logo}`;
      });
      this.list1 = res.department_1;
      this.list2 = res.department_2;
    },
    async getDesc() {
      const res = await getInstituteIntroduction({
        lang: self.langCode,
      });
      this.desc = res.projectDescription.description
    },
    setPageLanguage(_lang) {
      const lang = _lang.toLowerCase();
      this.title = this.introduction.title[lang];
      this.link = this.introduction.link[lang];
      this.sub_title1 = this.introduction.sub_title[lang][0];
      this.sub_title2 = this.introduction.sub_title[lang][1];
      this.sub_title0 = this.introduction.institute[lang];
    },
    changeLanguage(lang) {
      this.langCode = lang === "ZH" ? 0 : 1;
      this.setPageLanguage(lang);
      this.onSend();
    },
  },
};
</script>

<style scoped lang="less">
.list {
  width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .item {
    width: 585px;
    margin-bottom: 30px;
    background-color: #efedf4;
    padding: 30px 0;
    .logo {
      text-align: center;
      img {
        height: 120px;
      }
    }
    .name {
      margin-top: 20px;
      text-align: center;
      font-size: 18px;
      font-weight: 600;
      color: #255389;
    }
    .desc {
      margin-top: 20px;
      height: 193px;
      overflow: hidden;
      color: #717171;
      padding: 0 30px;
      line-height: 21px;
    }
    .link {
      width: 250px;
      margin: 0 auto;
      margin-top: 20px;
      color: #fff;
      text-align: center;
      a {
        display: block;
        height: 40px;
        line-height: 40px;
        background-color: #255389;
        color: #fff;
      }
      a:hover {
        background-color: #295e9a;
      }
    }
  }
}
.desc-main {
  width: 1200px;
  margin: 0 auto;
  padding-top: 15px;
  color: #333;
  line-height: 1.6;
  font-size: 14px;
  font-weight: 600;
}
</style>
